import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
# 第二种方式 Select类
# 打开浏览器访问网址
driver = webdriver.Chrome()
driver.get("https://sahitest.com/demo/selectTest.htm")

time.sleep(2)
s1 = driver.find_element(By.ID, "s1")
# 实例化select对象
select = Select(s1)

# 选择option
# 根据索引选择
select.select_by_index(1)
time.sleep(2)
# 根据value值选择
select.select_by_value('48')
time.sleep(2)
# 根据文本来选择
select.select_by_visible_text('Fax')


# 退出浏览器
time.sleep(2)
driver.quit()